home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 25 / CU Amiga Magazine's Super CD-ROM 25 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-08].iso / CUCD / Programming / QuakeTools / src / util / vis.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-11  |  3.0 KB  |  117 lines

  1. #define    LIBQTOOLS_CORE
  2. #define    LIBQBUILD_CORE
  3. #include <libqtools.h>
  4. #include <libqbuild.h>
  5.  
  6. struct memory bspStatic;
  7. struct memory *bspMem = &bspStatic;
  8.  
  9. extern int bitbytes;                                       // (num_visleafs+63)>>3
  10. extern int bitlongs;
  11. extern int c_chains;
  12. extern int c_leafsee, c_portalsee;
  13. extern int c_portalskip, c_leafskip;
  14. extern int c_portaltest, c_portalpass, c_portalcheck;
  15. extern int c_vistest, c_mighttest;
  16. extern int count_sep;
  17. extern int leafon;                                       // the next leaf to be given to a thread to process
  18. extern int originalvismapsize;
  19. extern int testvislevel;
  20. extern int totalvis;
  21. extern unsigned char *uncompressed;                               // [bitbytes*num_visleafs]
  22. extern unsigned char portalsee[MAX_PORTALS];
  23.  
  24. extern void CalcVis(__memBase);
  25. extern void CalcAmbientSounds(__memBase);
  26.  
  27. /*
  28.  * ===========
  29.  * main
  30.  * ===========
  31.  */
  32. int main(int argc, char **argv)
  33. {
  34.   char portalfile[NAMELEN_PATH];
  35.   char source[NAMELEN_PATH];
  36.   int i;
  37.   FILE *bspFile;
  38.   int visOptions = 0;
  39.  
  40.   memset(bspMem, 0, sizeof(struct memory));
  41.   if (!setjmp(eabort)) {
  42.     mprintf("----- Vis ---------------\n");
  43.  
  44.     for (i = 1; i < argc; i++) {
  45.       if (!strcmp(argv[i], "-fast")) {
  46.         mprintf("fastvis = true\n");
  47.         visOptions |= VIS_FAST;
  48.       }
  49.       else if (!strcmp(argv[i], "-level")) {
  50.         testvislevel = atoi(argv[i + 1]);
  51.         mprintf("testvislevel = %i\n", testvislevel);
  52.         i++;
  53.       }
  54.       else if (!strcmp(argv[i], "-v")) {
  55.         mprintf("verbose = true\n");
  56.         visOptions |= VIS_VERBOSE;
  57.       }
  58.       else if (argv[i][0] == '-')
  59.         Error("Unknown option \"%s\"", argv[i]);
  60.       else
  61.         break;
  62.     }
  63.  
  64.     if (i != argc - 1)
  65.       Error("usage: vis [-level 0-4] [-fast] [-v] bspfile");
  66.  
  67.     strcpy(source, argv[i]);
  68.     ReplaceExt(source, "bsp");
  69.     if((bspFile = fopen(source, READWRITE_BINARY_OLD))) {
  70.       char *prtBuf;
  71.     
  72.       bspMem = LoadBSP(bspFile, ALL_LUMPS & ~LUMP_VISIBILITY);
  73.       bspMem->visOptions = visOptions;
  74.       AllocClusters(bspMem, LUMP_VISIBILITY);
  75.       
  76.       strcpy(portalfile, argv[i]);
  77.       ReplaceExt(portalfile, "prt");
  78.       
  79.       prtBuf = (char *)GetVoid(portalfile);
  80.       LoadPortals(prtBuf);
  81.       tfree(prtBuf);
  82.  
  83.       originalvismapsize = num_visportals * ((num_visportals + 7) / 8);
  84.       bitbytes = ((num_visportals + 63) & ~63) >> 3;
  85.       bitlongs = bitbytes / sizeof(long);
  86.  
  87.       if(!(uncompressed = (char *)kmalloc(bitbytes * num_visleafs)))
  88.         Error("Vis: failed to allocate bitbytes!\n");
  89.  
  90. //    CalcPassages ();
  91.       CalcVis(bspMem);
  92.  
  93.       mprintf("%5i c_chains\n", c_chains);
  94.       mprintf("%5i visdatasize (compressed from %i)\n", bspMem->visdatasize, originalvismapsize);
  95.  
  96.       CalcAmbientSounds(bspMem);
  97.  
  98.       WriteBSP(bspFile, bspMem);
  99.     
  100.       for(i = 0; i < num_visleafs; i++)
  101.         if(leafs[i])
  102.           FreeLeaf(leafs[i]);
  103.       for(i = 0; i < (num_visportals * 2); i++)
  104.         if(portals[i].winding);
  105.           FreeWinding(portals[i].winding);
  106.       tfree(leafs);
  107.       tfree(portals);
  108.       kfree();
  109.  
  110.       FreeClusters(bspMem, 0);
  111.       fclose(bspFile);
  112.     }
  113.   }
  114.  
  115.   return 0;
  116. }
  117.